<h2>用户密码</h2>
<div id="centra-mima-form"
     data-topple="hsForm"
     data-save-url="centra/mine/save.act">
    <form action="" method="POST" autocomplete="off">
        <input type="hidden" name="id" data-fn/>
        <div style="height: 0; overflow: hidden;">
            <input type="text"     name="_u"/>
            <input type="password" name="_s"/>
        </div>
        <div class="form-group">
            <label class="control-label">原口令</label>
            <input type="password" name="passolde" class="form-field form-control" required="required"/>
        </div>
        <div class="form-group">
            <label class="control-label">新口令</label>
            <input type="password" name="password" class="form-field form-control" required="required" data-relate="passcode"/>
        </div>
        <div class="form-group">
            <input type="password" name="passcode" class="form-field form-control" required="required" data-repeat="password" data-error="请重复输入口令" placeholder="请重复输入口令"/>
        </div>
        <div class="form-group form-control-static" style="padding-top: 0;">
            <a href="javascript:;" class="new-password">生成密码</a>
            <!--a href="javascript:;" class="new-authcode pull-right" title="API Key 用于以当前用户身份调用接口">获取/重置 API Key</a-->
        </div>
        <div class="form-group">
            <button type="submit" class="commit btn btn-primary">提交</button>
            <button type="button" class="cancel btn btn-link"   >取消</button>
        </div>
    </form>
</div>
<script type="text/javascript">
    (function($) {
        var context = H$("#centra-mima-form");

        context.on("click", ".new-password", function() {
            newPassword(32);
        });
        function newPassword(l) {
            var pw = getPassword(l);
            $.hsMask({
                mode : "warn",
                html : "请务必记住新的密码, 提交后将以不可逆加密的形式进行存储."
            }, {
                label: "更换",
                glass: "btn-default",
                click: function(ev) {
                    ev.preventDefault();
                    pw = getPassword(l);
                    $(this).closest(".modal").find(".code").text(pw);
                }
            }, {
                label: "拷贝",
                glass: "btn-default",
                click: function(ev) {
                    ev.preventDefault();
                    $(this).closest(".modal").find(".code").hsCopy();
                }
            }, {
                label: "确认",
                glass: "btn-primary",
                click: function() {
                    context.find("[name=password],[name=passcode]").val(pw);
                }
            }).find(".alert-title").html('新密码: <b class="code">'+ pw +'</b>');
        }
        function getPassword(l) {
            var cs = [
                ['A', 'B', 'C', 'D', 'E', 'F', 'G',
                 'H', 'I', 'G', 'K', 'M', 'N',
                 'P', 'Q', 'R', 'S', 'T',
                 'U', 'V', 'W', 'X', 'Y'],
                ['a', 'b', 'c', 'd', 'e', 'f', 'g',
                 'h', 'i', 'g', 'k', 'm', 'n',
                 'p', 'q', 'r', 's', 't',
                 'u', 'v', 'w', 'x', 'y'],
                ['3', '4', '5', '6', '7', '8', '9'],
                ['@', '#', '$', '%', '&']
            ];
            var ps = [];
            var hasNum = false; // 至少含有一个数字
            var hasSym = false; // 至少含有一个符号
            for(var i = 0; i < l; i ++) {
                var j = Math.floor(Math.random() * 100);
                var x = j % cs.length;
                if (x === 2 && !hasNum) {
                    hasNum = true;
                } else
                if (x === 3 && !hasSym) {
                    hasSym = true;
                }
                if (i === 6 && !hasNum) {
                    x = 2;
                } else
                if (i === 7 && !hasSym) {
                    x = 3;
                }
                var y = j % cs[x].length;
                ps.push (cs[x][y]);
            }
            return ps.join("");
        }

        /*
        // 暂不开放
        if (! H$('!centra/mine/auth.act')) {
            context.find(".new-authcode").remove();
        }
        context.on("click", ".new-authcode", function() {
            newAuthCode( );
        });
        function newAuthCode() {
            $.hsMask({
                title: "获取/重置 API Key",
                text : "这将创建新的 API Key, 旧的将会失效(如果有). 确定要执行吗?",
                glass: "alert-danger",
                mode : "warn",
                focus: 2
            }, {
                label: "确定创建",
                glass: "btn-danger",
                click: function() {
                    $.hsAjax({
                        url: "centra/mine/auth.act",
                        dataType: "json",
                        success : function(rsp) {
                            rsp = hsResponse(rsp);
                            console.log(rsp.code);
                            if (rsp.ok) {
                                $.hsMask({
                                    html : "请记住并避免泄露, 此后将无法再查看.</p>",
                                    glass: "alert-success",
                                    mode : "warn"
                                }, {
                                    label: "确定并拷贝 API Key",
                                    glass: "btn-success",
                                    click: function() {
                                        $(this).closest(".modal").find(".code").hsCopy();
                                    }
                                }).find(".alert-title").html('API Key: <b class="code">'+ rsp.code +'</b>');
                            }
                        }
                    });
                }
            }, {
                label: "取消",
                glass: "btn-default"
            });
        }
        */
    })(jQuery);
</script>